/* Layout */
import Layout from '../components/layout/Index'

/**
 * 404
 */
export const pageError = {
  path: '*',
  name: '404',
  meta: {
    title: '404'
  },
  component: resolve => {
    require(['@/views/error/404'], resolve)
  }
}


/**
 * 500 系统错误
 */
export const serveError = {
  path: '/500',
  name: '500',
  meta: {
    title: '500'
  },
  component: resolve => {
    require(['@/views/error/500'], resolve)
  }
}

/**
 * 登录
 */
export const loginRouter = [
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录',
      isLogin: true
    },
    component: resolve => {
      require(['@/views/Login'], resolve)
    }
  }
]


/**
 * 主路由
 */
export const appRouter = [
  {
    path: '/',
    redirect: { name: 'login' },
    meta: {  title: '主页',  keepAlive: true},
    component: Layout,

    children: [
      {
        path: '/dashboard',
        meta: {
          title: '控制台',
          keepAlive: true
        },
        name: 'dashboard',
        component: resolve => {
          require(['@/views/dashboard/Index'], resolve)
        }
      },
    ]
  },

  {
    path:"/sys",
    name:'sys',
    redirect: '/user',
    meta:{title:'系统管理'},
    component: Layout,
    children:[
      {
        path: '/user',
        name: 'user',
        meta: { title: '用户管理' },
        component: () => import("@/views/User"),

      },
      {
        path: '/role',
        name: 'role',
        meta: { title: '角色管理' },
        component: () => import("@/views/Role"),
      },
      {
        path: '/menu',
        name: 'menu',
        meta: { title: '菜单管理' },
        component: () => import("@/views/Menu"),
      },
    ]
  },





  {
    path: '/pages',
    meta: {
      title: '页面',
      requiresAuth: true
    },
    name: 'pages',
    component: Layout,
    children: [
      {
        path: '404',
        meta: {
          title: '404页面不存在',
          requiresAuth: true,
          name: 'pages_404'
        },
        component: resolve => { require(['../views/error/404.vue'], resolve) }
      }
    ]
  }
]

export const routes = [serveError,pageError, ...loginRouter, ...appRouter]
